package com.yc.shopping.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.yc.shopping.util.DBHelper;

/**
 * 管理员表操作的Dao类
 * 
 * @author HiZzog
 *
 */
public class AdminDao {
	
	
	//登录操作
	/**
	 * 管理员登录
	 * @param aname
	 * @param pwd
	 * @return
	 * @throws SQLException
	 */
	public Map<String, Object> login(String aname,String pwd) throws SQLException{
		String sql = "select aid, aname ,pwd,atype,astate from tb_admin where aname = ? and pwd = ?";
		//调用DBHelper中的方法
		return DBHelper.selectOneMap(sql, aname,pwd);
	}
	
	//查看所有
	/**
	 * 查看所有管理员
	 * @return
	 * @throws SQLException
	 */
	public List<Map<String, Object>> findAll() throws SQLException{
		String sql = "select aid, aname ,pwd,atype,astate from tb_admin";
		return DBHelper.selectListMap(sql);
	}
	/**
	 * 修改状态
	 * @param aid 
	 * @param state 1 可用 2 禁用
	 * @return
	 * @throws SQLException 
	 */
	public int updateState(int aid,int state) throws SQLException {
		String sql = "update tb_admin set astate = ? where aid = ?";
		return DBHelper.update(sql,state,aid);
		
	}
}
